<template>
  <!-- 大客户线索管理->经销商大客户区域经理维护 -->
  <div>
    <!-- 搜索 -->
    <TopFilter  
      :list="topFilterInit"  
      :cols="3"  
      labelWidth="100"  
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
      ></TopFilter>
     <!-- table -->
    <FilterTable   ref="table" :columns="columns"   
       :fetchapi="fetchParams" 
       :isSelectColumn="isSelectColumn"
       :params="flterValue" :datakey="'records'"
       :onColumnsChange="columns => this.columns = columns">
      <template slot="controls" >
        <el-button size="small" type="primary" icon="el-icon-plus" @click="detailHandle">新增</el-button>
      </template>
   </FilterTable>
    <!-- 经销商弹窗 -->
  <BaseDialog title="经销商查询" :visible.sync="visibleDealer"
      width="1000px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}" >
      <dealer-madal  ref="addDialog" @close="closeHandler" />
   </BaseDialog>
   <Drawer  :visible.sync="visibleDrawer"
       ref="infoDrawerDrawer"
       title="新增大客户"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
      >
     <info-modal ref="infoDrawer" @close="infoClose" />
   </Drawer>
   
  </div>
</template>
<script>
import dealerMadal from '../areaBossPush/dealerMadal'
import infoModal from './info'
import { dictionary } from '@/utils/dictMixin';
import { PHONE_PATTERN } from '@/utils/validate' // 验证
export default {
  name: 'customerAdd',
  mixins: [dictionary],
  components: {
    infoModal,dealerMadal
  },
  data() {
    return {
      visibleDrawer:false,
      visibleDealer:false,
      isSelectColumn:false,
      infoId:null,
      topFilterInit:this.topFilterInitFun(),
      flterValue:{},  //参数
      columns:this.creatHeader(),
      fetchParams:null, //ipa 接口
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
      //搜索数据
      topFilterInitFun(){
        return [
            { type: 'INPUT',   label: '大客户事业部', fieldName: 'field1', placeholder: '请输入',initialValue: '' },
            { type: 'INPUT',   label: '区域经理姓名', fieldName: 'field71', placeholder: '请输入',initialValue: '' },
            { type: 'INPUT',  label: '经销商', fieldName: 'field9',  placeholder: '请选择', initialValue: '', 
             unitRender: () => {
                    return <el-button slot="append" icon="el-icon-search" onClick={() =>this.dealerHandle()}></el-button>
              },
            },
            { type: 'SELECT',  label: '状态', fieldName: 'field6',  placeholder: '请选择', initialValue: "", itemList:  this.createDictList('1008') }
        ]
      },
      //搜索获取数据
      changeHandle(val){
          this.flterValue=val
          console.log(val)
      },
      //table表头和数据源
      creatHeader(){
         return [
         {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
         },
         {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>编辑</el-button>
              </div>
            );
          }
        },
        { title: '状态',  dataIndex: 'field0', sorter: true,
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }},
        { title: '大客户事业部',  dataIndex: 'field1', sorter: true},
        { title: '区域经理代码',      dataIndex: 'field2', sorter: true},
        { title: '区域经理姓名',   dataIndex: 'field3', sorter: true},
        { title: '性别',    dataIndex: 'field4',  sorter: true},
        { title: '身份证号码',  dataIndex: 'field5',   sorter: true},
        { title: '手机',  dataIndex: 'field6', sorter: true},
        { title: '下属经销商数量',  dataIndex: 'field7',   sorter: true },
        { title: '创建时间',  dataIndex: 'field8',  sorter: true},
        { title: '更新时间',  dataIndex: 'field9', sorter: true}
        ]
      },
      // 经销商打开窗口 -传数据
      dealerHandle(){
        this.visibleDealer=true
      },
      // 经销商关闭窗口 -返回数据
      closeHandler(data){
        //返回数据逻辑自己写
        this.topFilterInit[2].initialValue='选择经销商'
        this.visibleDealer=data.visible //关闭弹窗
    },
    //新增、编辑
    detailHandle(row){
      this.visibleDrawer=true
      this.$nextTick(() => {
       this.$refsinfoDrawerDrawer.$refs.infoDrawer.openInit('1001')
      });
    },
    //关闭详情
    infoClose(){
      this.visibleDrawer=false
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
     collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
